
var mData=null
var mItemIndex=-1
var mIsOnBuy=false;

 function SetItemData(data)
 {
     // $.Msg(data)
     mData=data
     mIsOnBuy=false;
     $.GetContextPanel().style.visibility="visible";
     Show(false)

     var abilityNameELE=$( "#AbilityName" )
     if(!mData.key){
         $.GetContextPanel().style.visibility='collapse';
         return
     }
     else {
         $.GetContextPanel().style.visibility='visible';
     }

     abilityNameELE.text = $.Localize("#DOTA_Tooltip_ability_"+mData.key)
     $( "#AbilityImg" ).abilityname=mData.key
     var descText=$.Localize("#DOTA_Tooltip_ability_"+mData.key+"_Description")
     if(descText==="DOTA_Tooltip_ability_"+mData.key+"_Description") {
         descText = $.Localize("#DOTA_Tooltip_ability_" + mData.key + "_Lore")
         if (descText === "DOTA_Tooltip_ability_" + mData.key + "_Lore") {
             descText = "...."
         }
     }


     $( "#AbilityDes1" ).text = descText.replace(/%.*%/ig, '')
     // $( "#AbilityPrice" ).text="x"+mData.price
     $( "#AbilityType" ).SetHasClass("AbilityTypeAttributes",false)
     $( "#AbilityType" ).SetHasClass("AbilityTypeUltimate",false)
     $( "#AbilityType" ).SetHasClass("AbilityTypeBasic",false)
     $( "#AbilityNameContainer" ).SetHasClass("AbilityNameAttributes",false)
     $( "#AbilityNameContainer" ).SetHasClass("AbilityNameBasic",false)
     $( "#AbilityNameContainer" ).SetHasClass("AbilityNameUltimate",false)

     switch (mData.abilityType){
         case "DOTA_ABILITY_TYPE_ATTRIBUTES":
             $( "#AbilityType" ).SetHasClass("AbilityTypeAttributes",true)
             $( "#AbilityNameContainer" ).SetHasClass("AbilityNameAttributes",true)
             $( "#AbilityType" ).text = $.Localize("#AbilitiesShop_AbilityType_Attributes")
             $( "#AbilitiesShopItemBackRoot" ).style.backgroundImage=" url(\"file://{resources}/images/custom_game/cardback_attr.png\")";
             break;
         default:
         case "DOTA_ABILITY_TYPE_BASIC":
             $( "#AbilityType" ).SetHasClass("AbilityTypeBasic",true)
             $( "#AbilityNameContainer" ).SetHasClass("AbilityNameBasic",true)
             $( "#AbilityType" ).text = $.Localize("#AbilitiesShop_AbilityType_Basic")
             $( "#AbilitiesShopItemBackRoot" ).style.backgroundImage=" url(\"file://{resources}/images/custom_game/cardback_bas.png\")";
             break;
         case "DOTA_ABILITY_TYPE_ULTIMATE":
             $( "#AbilityType" ).SetHasClass("AbilityTypeUltimate",true)
             $( "#AbilityNameContainer" ).SetHasClass("AbilityNameUltimate",true)
             $( "#AbilityType" ).text = $.Localize("#AbilitiesShop_AbilityType_Ultimate")
             $( "#AbilitiesShopItemBackRoot").style.backgroundImage=" url(\"file://{resources}/images/custom_game/cardback_ult.png\")";
             break;
     }
 }

 function GetItemData() {
     return mData
 }


function Show(front) {
    if(front==true){
        $.GetContextPanel().FindChildTraverse("AbilitiesShopItemRoot").style.transform=  'scale3d( 1,1,1)';
        $.GetContextPanel().FindChildTraverse("AbilitiesShopItemRoot").style.position=  '0px 0px 0px;';
        $.GetContextPanel().FindChildTraverse("AbilitiesShopItemBackRoot").style.transform=  'scale3d( 1,1,1)';
        $.GetContextPanel().FindChildTraverse("AbilitiesShopItemBackRoot").style.position=  '0px 0px 0px;';
    }
    else {
        $.GetContextPanel().FindChildTraverse("AbilitiesShopItemRoot").style.transform=  'scale3d( -1,1,-1)';
        $.GetContextPanel().FindChildTraverse("AbilitiesShopItemRoot").style.position=  '0px 0px 0px;';
        $.GetContextPanel().FindChildTraverse("AbilitiesShopItemBackRoot").style.transform=  'scale3d( -1,1,-1)';
        $.GetContextPanel().FindChildTraverse("AbilitiesShopItemBackRoot").style.position=  '0px 0px -3px;';
    }

}

function OnSelected() {
    if(mData===null){
        return
    }
    $.Msg(mData)
    $.GetContextPanel().GetParent().OnSelectedItem($.GetContextPanel(),mData)
}

function OnBuy(cb) {
     if(mIsOnBuy!=true){
         mIsOnBuy=true;
         Show(true);
         Game.EmitSound("playercard.flip");
         $.Schedule(.5, function () {
             $.GetContextPanel().style.position = '700px 550px 0px';
             $.GetContextPanel().style.transform = 'scale3d( 0.001,0.001,0.001)';
             $.Schedule(.4,function () {
                 $.GetContextPanel().style.visibility="collapse"
                 $.GetContextPanel().style.position = '0px 0px 0px';
                 $.GetContextPanel().style.transform = 'scale3d( 1,1,1)';
                 if (cb){
                     cb()
                 }
             })
         });
     }
}

(function()
{
    $.GetContextPanel().OnBuy = OnBuy;
    $.GetContextPanel().SetItemData = SetItemData;
    $.GetContextPanel().GetItemData = GetItemData;
})();